#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

/*char u_buf[100] = "i am user data!";
int main(int argc, const char *argv[])
{
	/*your code
	int fd;
	fd = open("/dev/mycdev", O_RDWR);
	if (fd < 0) {
		perror("open");
		return -1;
	}
	read(fd, u_buf, sizeof(u_buf));
	write(fd, u_buf, sizeof(u_buf));
	close(fd);
	return 0;
}*/



int data = 0; //1 red 2 green 3 blue 0 off

int main(int argc, const char* argv[])
{
	int fd;
	fd = open("/dev/hello", O_RDWR);
	if (fd == -1) {
		printf("open /dev/hello error\n");
		return -1;
	}

	while (1) {
		printf("input led code > ");
		scanf("%d", &data);

		write(fd, &data, sizeof(data));
		data = 0;
		read(fd, &data, sizeof(data));

		switch (data) {
		case 1:printf("RGB LED : RED\n");
			break;
		case 2:printf("RGB LED : GREEN\n");
			break;
		case 3:printf("RGB LED : BLUE\n");
			break;
		default:printf("RGB LED : OFF\n");
			break;
		}
	}
	close(fd);

	return 0;
}